<template>
  <a-card :bordered="false" title>
    <p style="text-align: center; font-size: 20px">产成品入库列表</p>

    <!-- 搜索 -->
    <a-form v-bind="layout">
      <a-row>
        <!-- 制单日期 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单日期" ref="sort" prop="sort">
            <a-range-picker
              style="width: 100%"
              v-model="searchForm.sort"
              @change="
                (a, b) => {
                  this.searchForm.a = a;
                  this.searchForm.beginDate = b[0];
                  this.searchForm.endDate = b[1];
                }
              "
            />
          </a-form-model-item>
        </a-col>

        <!-- 单据号 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <a-select
              v-model="searchForm.document"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="(item, index) in documentList"
                :key="index"
                :value="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <!-- 仓库名称 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <a-select
              v-model="searchForm.depotId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="item.depotId"
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col>

        <!-- 所属单位 -->
        <!-- <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="所属单位">
            <a-select
              v-model="searchForm.storageUnit"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="item.depotId"
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- 交货单位 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="交货单位">
            <a-tree-select
              v-model="searchForm.deliveryUnitName"
              style="width: 100%"
              allow-clear
              :tree-data="deliveryUnitList"
              showSearch
              :replace-fields="replaceFields"
              @change="
                (value, b, extra) => {
                  this.searchForm.deliveryUnitName = value;
                  this.searchForm.b = b;
                  this.searchForm.deliveryUnit = extra.triggerNode.eventKey;
                }
              "
            >
            </a-tree-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="审核状态">
            <a-select v-model="searchForm.auditMark" style="width: 100%">
              <a-select-option
                v-for="(item, index) in danjuzhuangtailist"
                :value="item.value"
                :key="index"
              >
                {{ item.title }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单人">
            <a-select
              v-model="searchForm.prepared"
              style="width: 100%"
              showSearch
            >
              <a-select-option
                v-for="(item, index) in PreparedyList"
                :key="index"
                :value="item.id"
              >
                {{ item.id_dictText }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="是否入库">
            <a-select v-model="searchForm.whetherInOutMark">
              <a-select-option value="1">是</a-select-option>
              <a-select-option value="0">否</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col
          :xl="8"
          :lg="8"
          :md="12"
          :sm="24"
          :xs="24"
        >
          <a-form-model-item label="同步状态">
            <a-select v-model="searchForm.isSynchronized" style="width: 100%">
              <a-select-option
                v-for="item in isSynchronizedList"
                :value="item"
                :key="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="入库时间" ref="sort" prop="sort">
            <a-range-picker
              style="width: 100%"
              v-model="searchForm.inoutTime"
              @change="
                (a, b) => {
                  this.searchForm.a = a;
                  this.searchForm.beginTime = b[0];
                  this.searchForm.endTime = b[1];
                }
              "
            />
          </a-form-model-item>
        </a-col> -->
      </a-row>
      <a-row>
        <!-- 存货名称 -->
        <a-col
          style="margin-left: -130px"
          :xl="16"
          :lg="16"
          :md="12"
          :sm="24"
          :xs="24"
        >
          <a-form-model-item label="存货名称">
            <a-select
              v-model="searchForm.inventoryName"
              showSearch
              @search="handleSearch"
              style="width: 100%"
              @change="
                (val) => {
                  const arr = val.split('|');
                  this.searchForm.inventoryId = arr[0];
                  this.searchForm.inventoryNo = arr[1];
                  this.searchForm.inventoryName = arr[2];
                }
              "
            >
              <a-select-option
                v-for="(item, index) in goodsList"
                :key="index"
                :value="
                  item.inventoryId +
                  '|' +
                  item.inventoryNo +
                  '|' +
                  item.inventoryName +
                  '|' +
                  item.specificationsModel +
                  '|' +
                  item.unit
                "
                >{{ item.inventoryNo }} {{ item.inventoryName }}
                {{ item.specificationsModel }} {{ item.unit }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form>
    <a-form>
      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24" align="right">
          <a-button type="primary" @click="Search()">查询</a-button>
          <a-button style="margin-left: 8px" @click="Reset()">重置</a-button>
          <a-button style="margin-left: 8px" @click="exportToExcel"
          >导出</a-button
        >
        </a-col>
      </a-row>
    </a-form>
    <!-- 
    <div style="float:right">
      <a-button type="danger" style="margin-left: 8px" @click="moreDelete">
        批量删除
      </a-button>
      <a-button type="" style="margin-left: 8px" @click="exportAll">
        全部导出
      </a-button>
      <a-button type="primary" style="margin-left: 8px" @click="export_Table">
        批量导出
      </a-button>
    </div> -->

    <!-- :row-selection="rowSelection" -->
    <!-- 搜索下的表格 -->
    <a-table
      v-cloak
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      @change="handleTableChange"
      style="margin-top: 20px"
      :scroll="{ x: 1900 }"
      size="middle"
    >
      <span slot="document" slot-scope="text, record">
        <a @click="RouterJump(record)"> {{ text }} </a>
      </span>
      <span slot="seeRemarkShelf" slot-scope="text, records">
        <a @click="showRemarkShelf(records)">点击查看</a>
      </span>
      <span slot="shelfNo" slot-scope="text, records">
        <a @click="showShelfNo(records)">点击查看</a>
      </span>
      <span slot="options" slot-scope="text, record">
        <a-popconfirm
          v-if="record.auditMark_dictText == '未审核'"
          title="确定删除?"
          ok-text="删除"
          cancel-text="我再想想"
          @confirm="Delete(record.id)"
        >
          <a href="#">删除</a>
        </a-popconfirm>

        <a v-if="record.auditMark_dictText == '已审核'" style="color: #666666">
          <a-tooltip>
            <template slot="title"> 不允许删除 </template>
            删除
          </a-tooltip>
        </a>
      </span>
      <!-- <span slot="action" slot-scope="text, record">
        <a @click="showDetailModal(record)">详情</a>
        <a-divider type="vertical" />
        <a @click="Delete(record.id)">删除</a>
      </span> -->
    </a-table>
    <a-modal
      title="入库货架"
      :visible="visible1"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel1"
    >
      {{ this.remarkShelf }}
    </a-modal>
    <a-modal
      title="入库货架"
      :visible="visible2"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel2"
      @ok="addgoods_Ok"
    >
      {{ this.shelfNo }}
    </a-modal>
  </a-card>
</template>
<script>
import { CaiGouRuKuHttp } from "@/services/modules/RuKuGuGuanLi/CaiGouRuKu";
import { CommonAjax } from "@/services/modules/common";

const cgrkHttp = new CaiGouRuKuHttp(); // 采购入库
const comHttp = new CommonAjax(); // 公用接口

const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
    width: "50px",
  },
  {
    title: "日期",
    dataIndex: "documentDate",
    key: "documentDate",
    align: "center",
    width: "90px",
  },
  {
    title: "审核标志",
    dataIndex: "auditMark_dictText",
    key: "auditMark_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "同步用友",
    dataIndex: "isSynchronized",
    key: "isSynchronized",
    align: "center",
    width: "80px",
  },
  {
    title: "反审核",
    dataIndex: "isAntiAudit",
    key: "isAntiAudit",
    align: "center",
    width: "80px",
  },

  {
    title: "单据号",
    dataIndex: "document",
    key: "document",
    align: "center",
    width: "110px",
    scopedSlots: { customRender: "document" },
  },
  {
    title: "交货单位",
    dataIndex: "deliveryUnit",
    key: "deliveryUnit",
    align: "center",
    width: "80px",
  },
  {
    title: "仓库名称",
    dataIndex: "depotName",
    key: "depotName",
    align: "center",
    width: "100px",
  },
  // {
  //   title: "所属单位",
  //   dataIndex: "storageUnit",
  //   key: "storageUnit",
  //   align: "center",
  // },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
    width: "115px",
  },
  {
    title: "存货名称",
    dataIndex: "inventoryName",
    key: "inventoryName",
    align: "center",
    width: "120px",
  },
  {
    title: "规格型号",
    dataIndex: "invspec",
    key: "invspec",
    align: "center",
    width: "80px",
  },
  {
    title: "单位",
    dataIndex: "unit",
    key: "unit",
    align: "center",
    width: "80px",
  },
  {
    title: "单价",
    dataIndex: "unitPrice",
    key: "unitPrice",
    align: "center",
    width: "80px",
  },

  {
    title: "数量",
    dataIndex: "quantity",
    key: "quantity",
    align: "center",
    width: "80px",
  },

  {
    title: "金额",
    dataIndex: "money",
    key: "money",
    align: "center",
    width: "80px",
  },
  {
    title: "批次号",
    dataIndex: "batchNumber",
    key: "batchNumber",
    align: "center",
    width: "100px",
  },
  {
    title: "制单人",
    dataIndex: "singleProducer_dictText",
    key: "singleProducer_dictText",
    align: "center",
    width: "80px",
  },

  {
    title: "记账标志",
    dataIndex: "bookkeepingMark",
    key: "bookkeepingMark",
    align: "center",
    width: "80px",
  },

  {
    title: "源单号",
    dataIndex: "sourceNumber",
    key: "sourceNumber",
    align: "center",
    width: "110px",
  },
  {
    title: "负责人",
    dataIndex: "responsiblePerson_dictText",
    key: "responsiblePerson_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
    width: "100px",
  },
  {
    title: "货架",
    dataIndex: "seeRemarkShelf",
    key: "seeRemarkShelf",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "seeRemarkShelf" },
  },
  {
    title: "是否入库",
    dataIndex: "whetherInOutMark",
    key: "whetherInOutMark",
    align: "center",
    width: "80px",
  },
  {
    title: "入库货架",
    dataIndex: "shelfNo",
    key: "shelfNo",
    align: "center",
    scopedSlots: { customRender: "shelfNo" },
    width: "80px",
  },
  {
    title: "入库时间",
    dataIndex: "inoutTime",
    key: "inoutTime",
    align: "center",
    scopedSlots: { customRender: "inoutTime" },
    width: "80px",
  },
  {
    title: "操作",
    dataIndex: "options",
    key: "options",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "options" },
  },
];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(
      `selectedRowKeys: ${selectedRowKeys}`,
      "selectedRows: ",
      selectedRows
    );
  },
  onSelect: (record, selected, selectedRows) => {
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected, selectedRows, changeRows) => {
    console.log(selected, selectedRows, changeRows);
  },
};

export default {
  data() {
    return {
      isSynchronizedList: ["已同步", "未同步"],
      whetherInOutMarkList: ["是", "否"],
      replaceFields: {
        children: "syncDepartmentFilesEntityList",
        title: "deptname",
        value: "pkDeptdoc",
      },
      // ---------- 分页使用 -------------
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["5", "10", "20", "30"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
        showSizeChanger: true, // 显示页面条数改变
        showQuickJumper: true, // 显示快速跳转
      },
      queryParam: {
        //查询参数
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      },
      // 搜索栏布局
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
      },
      layout2: {
        labelCol: { span: 6 },
        wrapperCol: { span: 8 },
      },
      // 搜索列表
      searchForm: {
        whetherInOutMark: "", //是否出入库
        auditMark: "", //单据状态
        prepared: "",
        beginDate: "", // 制单日期
        endDate: "",
        document: "", // 单据号
        inventoryId: "", // 存货编码
        inventoryName: "",
        depotId: "", // 仓库名称
        // storageUnit: "", // 所属单位
        deliveryUnit: "", // 交货单位
        isSynchronized: "", //同步状态
        beginTime:"",//入库时间
        endTime:"",//入库时间
      },

      // 销售出库订单列表
      columns,
      dataSource: [],
      rowSelection,
      visible1: false, //修改弹窗
      visible2: false, //修改弹窗
      // 列表
      documentList: [], // 订单列表，返回所有的销售出库单
      storageList: [], // 仓库
      goodsList: [], // 存货
      saleDepartmentList: [], // 销售部门
      ALLOrderList: [], // 所有的订单列表,存储订单单号
      deliveryUnitList: [], //交货单位列表
      danjuzhuangtailist: [], //单据状态
      PreparedyList: [], //制单人列表

      // ---
      queryPathCache: "",

      remarkShelf: "",
      shelfNo: "",
    };
  },
  watch: {
    $route: function (to, form) {
      if (
        to.path == "/ProductInputList" &&
        form.path == "/ProductInputDetail"
      ) {
        console.log("--------- 更新视图 产成品入库列表  ----------");
        this.getOutStorageList();
      }

      if (to.path == "/ProductInputList" && form.path == "/ProductInput") {
        console.log("--------- 更新视图 产成品入库列表  ----------");
        this.getOutStorageList();
      }
    },
  },

  mounted() {
    // this.getGoodsList(); //获取存货仓库列表
    this.getDocumentList(); //获取单据号列表
    this.getOutStorageList();
    this.getStorageList(); // 仓库列表
    // this.getSaleDepartmentList(); // 获取销售部门
    this.getDeparmentTree(); // 获取部门列表
    this.getAuditMarkAndDocumentStatus(); //单据状态
    this.getPreparedyList(); //获取制单人列表
  },
  methods: {
    // 是否入库
    getwhetherInOutMark() {
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
    },
    // 获取制单人列表
    getPreparedyList() {
      comHttp.getPreparedyList().then((res) => {
        var pattern = new RegExp("[\u4E00-\u9FA5]+");

        console.log("获取制单人列表:::::", res);
        let data = res.result.list.filter((item) => {
          if (pattern.test(item.id)) {
            console.log(item.id);
          } else if (item.id == null) {
            console.log(item.id);
          } else {
            return item;
          }
        });
        console.log(data);
        this.PreparedyList = data;
      });
    },
    showRemarkShelf(records) {
      //查看货架按钮
      this.visible1 = !this.visible1;
      console.log(records);
      this.remarkShelf = records.remarkShelf;
    },
    showShelfNo(records) {
      this.shelfNo = [];
      //查看货架按钮
      this.visible2 = !this.visible2;
      console.log(records);

      comHttp.getqueryShelves("?inoutDetailId=" + records.twoId).then((res) => {
        this.shelfNo = res.result.map((item) => {
          return item.shelfNo;
        });
        this.shelfNo = this.shelfNo.length == 0 ? "未查询到数据" : this.shelfNo;
      });
    },
    handleCancel1() {
      // 修查看货架按弹窗取消
      this.visible1 = false;
    },
    handleCancel2() {
      // 修查看货架按弹窗取消
      this.visible2 = false;
    },
    async handleSearch(value) {
      //模糊查询
      var goodsList_invname = [];
      var goodsList_invspec = [];
      this.goodsList = [];
      console.log("value", value);
      let query = "?name=" + value;
      console.log("query", query);
      if (value == "" || value == null) {
        this.goodsList = [];
      } else {
        this.goodsList = [];
        await comHttp
          .getgetSearchInventoryInformationFile(query)
          .then((res) => {
            console.log("结果为", res);
            // this.goodsList = res.result;
            for (let i = 0; i < res.result.length; i++) {
              if (
                res.result[i].specificationsModel == "null" ||
                res.result[i].specificationsModel == null
              ) {
                res.result[i].specificationsModel = "";
              }
              if (res.result[i].unit == "null" || res.result[i].unit == null) {
                res.result[i].unit = "";
              }
              let data = {
                inventoryId: res.result[i].pkInvbasdoc, // 存货 id
                inventoryNo: res.result[i].invcode, //存货编码
                inventoryName: res.result[i].invname, //存货名称
                specificationsModel: res.result[i].invspec, //规格型号
                unit: res.result[i].measname, //单位
              };
              goodsList_invname.push(data);
            }
            console.log(" this.goodsList", this.goodsList);
          });

        let queryInventoryBySpec = "?invspec=" + value;
        //规格型号模糊查询
        await comHttp
          .getqueryInventoryBySpec(queryInventoryBySpec)
          .then((res) => {
            console.log("结果规格型号模糊查询", res);

            for (let i = 0; i < res.result.list.length; i++) {
              let data = {
                inventoryId: res.result.list[i].pkInvbasdoc, // 存货 id
                inventoryNo: res.result.list[i].invcode, //存货编码
                inventoryName: res.result.list[i].invname, //存货名称
                specificationsModel: res.result.list[i].invspec, //规格型号
                unit: res.result.list[i].measname, //单位
              };
              goodsList_invspec.push(data);
            }
          });

        //todo 合并去重函数
        await this.mergeArray(goodsList_invname, goodsList_invspec);
      }
    },
    //todo 合并去重函数
    mergeArray(arr1, arr2) {
      let arrs = [...arr1, ...arr2];

      //根据inventoryId去重
      let map = new Map();
      for (let item of arrs) {
        if (!map.has(item.inventoryId)) {
          map.set(item.inventoryId, item);
        }
      }
      this.goodsList = [...map.values()];
    },
    // 获取部门列表
    getDeparmentTree() {
      // console.log("获取部门列表hanshu===");
      comHttp.getDepartmentList().then((res) => {
        if (res.success) {
          console.log("获取部门树", res);
          let resetRes = res.result;
          this.resetDepartmentTree(resetRes);
          this.deliveryUnitList = resetRes;
          // console.log("this.depTree", this.depTree);
        }
      });
    },

    // 部门字典表中每一项vlaue 变成 title 为了方便搜索
    resetDepartmentTree(dep) {
      dep.forEach((item) => {
        // console.log("item", item);
        item.value = item.title;
        if (item.children) {
          this.resetDepartmentTree(item.children);
        }
      });
    },

    // 路由跳转函数
    RouterJump(record) {
      console.log("record", record);
      if (record.isAntiAudit === "已反审核") {
        // 制单人 == 当前登录人 && 审核人 ！= 当前登录人
        // 去修改吧！！！
        this.$router.push({
          path: "ProductInput",
          query: {
            document: record.document,
            auditMark: record.auditMark,
            singleProducer: record.singleProducer,
            isAntiAudit: record.isAntiAudit,
          },
        });
        return;
      }

      if (record.auditMark === 1) {
        // 已审核 跳转详情列表
        this.$router.push({
          path: "/ProductInputDetail",
          query: { document: record.document, auditMark: record.auditMark },
        });
      } else if (record.auditMark === 2) {
        // 未审核 跳转详情列表

        console.log("-------------------[]---------------------");
        console.log(record.singleProducer);
        console.log(record.inspector);
        console.log(this.$store.state.user.info.id);
        console.log("-------------------[]---------------------");
        if (
          record.singleProducer == this.$store.state.user.info.id &&
          record.inspector !== this.$store.state.user.info.id
        ) {
          // 制单人 == 当前登录人 && 审核人 ！= 当前登录人
          // 去修改吧！！！
          this.$router.push({
            path: "/ProductInput",
            query: {
              document: record.document,
              auditMark: record.auditMark,
              singleProducer: record.singleProducer,
            },
          });
          return;
        }

        this.$router.push({
          path: "/ProductInputDetail",
          query: { document: record.document, auditMark: record.auditMark },
        });
      }

      let a = true;
      if (a) return;

      console.log(":::::::routerjump.record::::", record);

      if (record.auditMark == 1) {
        // 已经审核
        this.alreadyCheckTag = false; // 不可审核
      } else if (record.auditMark == 2) {
        // 未审核
        this.alreadyCheckTag = true; // 可以审核
      }

      if (record.bookkeepingMark == 1) {
        // 已经审核
        this.alreadyRecordTag = false; // 不可审核
      } else if (record.bookkeepingMark == 2) {
        // 未审核
        this.alreadyRecordTag = true; // 可以审核
      }
      // 制单人
      if (record.singleProducer == this.$store.state.user.info.id) {
        console.log("这是制单人,能修改");
        this.$router.push({
          path: "ChanChengPin",
          query: {
            Id: record.id,
            alreadyCheckTag: false, // 是否审核标志
            alreadyRecordTag: false, // 是否记账标志
          },
        });
      }
      // 审核人
      else if (record.inspector == this.$store.state.user.info.id) {
        console.log("这是审核人,能审核,能提交");
        this.$router.push({
          path: "ChanChengPinDetail",
          query: {
            Id: record.id,
            alreadyCheckTag: this.alreadyCheckTag, // 是否审核标志
            alreadyRecordTag: this.alreadyRecordTag, // 是否记账标志
          },
        });
      }
      // 其余人员
      else {
        console.log("这是其余人员,仅能查看，不能审核和提交");
        this.$router.push({
          path: "ChanChengPinRuKuDetail",
          query: {
            Id: record.id,
            alreadyCheckTag: false, // 不可以审核
            alreadyRecordTag: false, // 不可以记账
          },
        });
      }
    },

    // 获取全局查询条件
    getQueryPath() {
      console.log(this.searchForm);

      let queryPath =
        "?pageNo=" +
        this.queryParam.page +
        "&inOutCategoryIdentification=2" +
        "&inOutIdentification=1" +
        "&document=" +
        this.searchForm.document + //单据号
        // "&deptId=" +
        // this.searchForm.deptId + //所属单位
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&endDate=" +
        this.searchForm.endTime +
        "&beginDate=" +
        this.searchForm.startTime + //
        "&auditMark=" +
        this.searchForm.auditMark +
        "&singleProducer=" +
        this.searchForm.prepared +
        "&isSynchronized=" +
        this.searchForm.isSynchronized;
      return queryPath; // 返回的查询条件
    },
    //获取存货名称列表
    getGoodsList() {
      let goodsList = [];
      cgrkHttp.getGoodsList().then((res) => {
        console.log("----- 获取存货名称列表 -----", res);
        for (let i = 0; i < res.result.records.length; i++) {
          let data = {
            title: res.result.records[i].inventoryName,
            value: res.result.records[i].inventoryNo,
            id: res.result.records[i].id,
          };
          this.goodsList.push(data);
        }
        console.log("----- goodsList -----", goodsList);
      });
      return goodsList;
    },
    // 获取单据号列表
    getDocumentList() {
      let queryPath = "?string=CPRK-";
      cgrkHttp.getDocumentList(queryPath).then((res) => {
        // console.log("获取采购入库单据号列表:::::", res);
        for (let i = 0; i < res.result.length; i++) {
          this.documentList.push(res.result[i]);
        }
      });
    },
    //单据状态
    getAuditMarkAndDocumentStatus() {
      comHttp.getAuditMarkAndDocumentStatus().then((res) => {
        this.danjuzhuangtailist = res.result;
        console.log(`单据状态:${this.danjuzhuangtailist}`);
      });
    },

    /**
     * @description: 获取住列表函数
     * @param {*}
     * @return {*}
     */

    getOutStorageList() {
      const { current, pageSize } = this.pagination;
      let _query = `?pageNo=${current}&pageSize=${pageSize}`;
      _query += `&inOutCategoryIdentification=2&inOutIdentification=1`;
      _query += this.queryPathCache;

      comHttp.getInOrOutStorageOrderAndGoodsList(_query).then((res) => {
        const pagination = { ...this.pagination };
        let records = res.result.records;

        pagination.total = res.result.total;
        pagination.pageSize = res.result.size;
        pagination.current = res.result.current;

        this.dataSource = [];
        this.ALLOrderList = [];
        this.pagination = pagination;

        console.log("--- [INFO] [产成品入库列表] --- \n", res);

        let dataSource = [];
        // let curDocument = "";

        for (let i = 0; i < records.length; i++) {
          // if (records[i].document === curDocument) {
          //   curDocument = records[i].document;
          //   records[i].document = "";
          // } else {
          //   curDocument = records[i].document;
          // }

          let data = {
            id: records[i].id,
            twoId: records[i].twoId,
            key: (res.result.current - 1) * res.result.size + i + 1,
            document: records[i].document,
            documentDate: records[i].documentDate, // 单据日期
            auditMark: records[i].auditMark, // 审核标志
            auditMark_dictText: records[i].auditMark_dictText, // 审核标志
            bookkeepingMark: records[i].bookkeepingMark_dictText, // 记账标志
            deliveryUnit: records[i].deliveryUnit_dictText, //交货单位
            depotName: records[i].storname, // 仓库名称
            // storageUnit: records[i].storageUnit_dictText, // 所属单位
            inventoryNo: records[i].invcode, // 存货编码
            inventoryName: records[i].invname, // 存货名称
            invspec: records[i].invspec, // 规格型号
            unit: records[i].measname, // 单位
            quantity: records[i].quantity, // 数量
            unitPrice: records[i].unitPrice, // 单价
            money: records[i].money, // 金额
            batchNumber: records[i].batchNumber, // 批次号
            giveaway_dictText: records[i].giveaway_dictText, // 是否赠品
            singleProducer: records[i].singleProducer, // 制单人Id
            singleProducer_dictText: records[i].singleProducer_dictText, // 制单人
            responsiblePerson_dictText: records[i].responsiblePerson_dictText, // 负责人
            inspector_dictText: records[i].inspector_dictText, // 审核人
            inspector: records[i].inspector, // 审核人Id
            // 记账标志
            sourceNumber: records[i].sourceNumber, // 源单号
            sendReceiveType: records[i].sendReceiveType, // 收发类别
            sendReceiveType_dictText: records[i].sendReceiveType_dictText, // 收发类别
            remark: records[i].remark, // 备注
            //反审核用
            isSynchronized: records[i].isSynchronized,
            isAntiAudit: records[i].isAntiAudit,
            //硬件用
            // whetherInOutMark: records[i].whetherInOutMark,//是否入库
            remarkShelf: records[i].remarkShelf, //货架
            shelfNo: records[i].shelfNo, //实际出入库货架d,
            inoutTime: records[i].inoutTime, //实际出入库时间
            whetherInOutMark: records[i].whetherInOutMark == 1 ? "是" : "否", //实际是否出入库标志
          };

          dataSource.push(data);
        }

        this.dataSource = dataSource;
      });
    },

    // ---------- 分页函数 -------------
    handleTableChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.queryParam.page = pagination.current;
      this.queryParam.size = pagination.pageSize;
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
    },

    /**
     * @description:  --- 查询函数 ---
     * @param {*}
     * @return {*}
     */

    Search() {
      const searchForm = this.searchForm;
      let query = "";
      console.log(searchForm);

      if (searchForm.beginDate) {
        query += `&beginDate=${searchForm.beginDate}`;
      }
      if (searchForm.endDate) {
        query += `&endDate=${searchForm.endDate}`;
      }
      if (searchForm.beginTime) {
        query += `&beginTime=${searchForm.beginTime}`;
      }//入库时间
      if (searchForm.endTime) {
        query += `&endTime=${searchForm.endTime}`;
      }
      if (searchForm.document) {
        query += `&document=${searchForm.document}`;
      }
      if (searchForm.inventoryId) {
        query += `&inventoryId=${searchForm.inventoryId}`;
      }
      if (searchForm.depotId) {
        query += `&depotId=${searchForm.depotId}`;
      }
      if (searchForm.storageUnit) {
        query += `&storageUnit=${searchForm.storageUnit}`;
      }
      if (searchForm.deliveryUnit) {
        query += `&deliveryUnit=${searchForm.deliveryUnit}`;
      }
      if (searchForm.prepared) {
        query += `&singleProducer=${searchForm.prepared}`;
      }
      if (searchForm.auditMark && searchForm.auditMark !== "3") {
        query += `&auditMark=${searchForm.auditMark}`;
      }
      if (searchForm.isSynchronized) {
        query += `&isSynchronized=${searchForm.isSynchronized}`;
      }
      if (searchForm.whetherInOutMark) {
        query += `&whetherInOutMark=${searchForm.whetherInOutMark}`;
      }
      this.queryPathCache = query;
      this.getOutStorageList();
    },

    Reset() {
      this.searchForm = {
        
        beginDate: "", // 制单日期
        endDate: "",
        document: "", // 单据号
        inventoryId: "", // 存货编码
        depotId: "", // 仓库名称
        // storageUnit: "", // 所属单位
        deliveryUnit: "", // 交货单位
        isSynchronized: "",
        prepared: "",
        beginTime:"",
        endTime:"",
      };

      this.pagination = {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["10"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
      };
      this.queryPathCache = "";

      this.getOutStorageList();
    },

    // -------------- 完成 ---------------------
    // 获取仓库列表
    getStorageList() {
      this.storageList = [];
      // 获取仓库名称
      comHttp.getStorageName().then((res) => {
        console.log("获取所有仓库", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            depotName: res.result[i].storname,
            depotNo: res.result[i].storcode,
            depotId: res.result[i].pkStordoc,
          };
          this.storageList.push(data);
        }
      });
    },
    // 获取仓库编码
    changeDepotId(value, option) {
      this.searchForm.depotId = option.key;
      console.log("仓库id::::", this.searchForm.depotId);
    },

    // 获取存货id
    changeinventoryId(value, option) {
      this.searchForm.inventoryId = option.key;
      console.log("存货id::::", this.searchForm.inventoryId);
    },
    // 获取所属单位id
    changestorageUnitId(value, option) {
      this.searchForm.storageUnitId = option.key;
      console.log("所属单位id::::", this.searchForm.storageUnitId);
    },

    // 获取销售部门列表
    getSaleDepartmentList() {
      this.saleDepartmentList = [];
      comHttp.getSaleDepartment().then((res) => {
        console.log(" [INFO] [交货单位 list] \n ", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            value: res.result[i].value,
            title: res.result[i].title,
          };
          this.saleDepartmentList.push(data);
        }
      });
    },
    //获取部门id
    changedeptId(value, option) {
      this.searchForm.deptId = option.key;
      console.log("部门id::::", this.searchForm.deptId);
    },
    // 获取时间段
    getRangeTime(date, dateString) {
      this.searchForm.startTime = dateString[0];
      this.searchForm.endTime = dateString[1];
    },

    //  重置当前页码及页码参数
    resetPagination() {
      this.pagination = {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ["10"], //每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
      };
      //查询参数
      this.queryParam = {
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      };
    },
    // 删除
    Delete(id) {
      cgrkHttp.deleteInOrOutStorageOrderAndGoods("?id=" + id).then((res) => {
        if (res && res.code === 200) {
          this.$message.success("删除成功");
          this.getOutStorageList();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
    addgoods_Ok() {
      this.visible2 = false;
    },

    // 导出列表
    exportToExcel() {
      this.queryPath =
        "?inOutCategoryIdentification=2" +
        "&inOutIdentification=1" +
        "&document=" +
        this.searchForm.document + //单据号
        // "&deptId=" +
        // this.searchForm.deptId + //所属单位
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&endDate=" +
        this.searchForm.endTime +
        "&beginDate=" +
        this.searchForm.startTime + //
        "&auditMark=" +
        this.searchForm.auditMark +
        "&singleProducer=" +
        this.searchForm.prepared +
        "&isSynchronized=" +
        this.searchForm.isSynchronized;
      comHttp
        .exportProductIn(this.queryPath)
        .then((response) => {
          //如果后端返回的result是进过Blob处理的，直接 window.URL.createObjectURL(result)，如果没有，就需要先实例化new Blod处理之后再window.URL.createObjectURL(blob)。
          //文件名 文件保存对话框中的默认显示
          let fileName = "产成品入库单.xls";
          let data = response.data;
          if (!data) {
            return;
          }
          console.log(response);
          //构造a标签 通过a标签来下载
          let url = window.URL.createObjectURL(new Blob([data]));
          let a = document.createElement("a");
          a.style.display = "none";
          a.href = url;
          //此处的download是a标签的内容，固定写法，不是后台api接口
          a.setAttribute("download", fileName);
          document.body.appendChild(a);
          //点击下载
          a.click();
          // 下载完成移除元素
          document.body.removeChild(a);
          // 释放掉blob对象
          window.URL.revokeObjectURL(url);
        });
    },
  },
};
</script>
<style scoped lang="less">
.avatar-uploader > .ant-upload {
  width: 160px;
  height: 160px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
textarea {
  border: 0;
  border-radius: 5px;
  border: 1px #d9d9d9 solid;
  width: 100%;
  height: 100px;
  padding: 10px;
  resize: none;
}
#feng_kong_cuo_shi_1 {
  width: 700px;
}
</style>